﻿@model Leiktuther.Models.GameInstance
@{
    ViewBag.Title = "OlsenOlsen - " + Model.Name;
}
<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/cardstyle.css")" />
<script src="@Url.Content("~/Scripts/cards.js")"></script>

<h2>Olsen Olsen @Model.Name</h2>
<div id="cardArea">
    <h2>Spil á hönd</h2>
    <div id="deck01"></div>
    <div id="deck02"></div>
    <div id="deck03"></div>
    <div id="deck04"></div>
</div>

<div id="playTable">
    <div class="card" id="deckurinn">
        <div id="cardDock"></div>
    </div>
    <div class="deckOfCards"></div>
    <div id="seat01">    </div>
    <div id="seat02">    </div>
    <div id="seat03">    </div>
    <div id="seat04">    </div>
</div>
<button id="deal">Byrjum leik</button>

<div id="chatIt">
    @Html.Partial("_ChatWindow")
</div>

<script>
    $(function () {
        var group = '@(Model.ID)';
        // var playerIndex = @ViewData["PlayerCount"];
        var hub = $.connection.gameHub;


        $.connection.hub.start().done(function () {
            hub.server.join(group);
        });
    });

var deck, discards, player01, player02, numPlayers = 2;
        window.onload = init;
        function init() {
            deck = new Stack();
            discards = new Stack();
            player01 = new Stack();
            player02 = new Stack();

            deck.makeDeck(1);
            deck.shuffle(21);
        }

        function turnOverDeck() {
            var j = discards.cardCount();
            for (i = 0; i < j; i++) {
                deck.addCard(discards.cards[i]);
            }
        }

        $("#cardDock").click(function () {
            alert("klikkaður");
            player01.addCard(discards.cards[j]);
            $("#cardDock .card").appendTo("#deck01");
        });
        var m = 0;
        $(".deckOfCards").click(function () {
            if (deck.cardCount() > 0) {
                discards.addCard(deck.deal());
                $(discards.cards[m].createNode()).appendTo("#cardDock");
                m++;
            }
            else {
                turnOverDeck();
                $("#cardDock .card").remove();
            }
        });

        $("#deal").click(function () {
            var node, leftIncr = 5;

            for (i = 0; i < 5; i++) {
                player01.addCard(deck.deal());
                player02.addCard(deck.deal());
                node = player01.cards[i].createNode();
                node.style.left = leftIncr + "px";
                $(node).appendTo("#deck01");
                node = player02.cards[i].createNode();
                node.style.left = leftIncr + "px";
                $(node).appendTo("#deck02");
                leftIncr = leftIncr + 20;
            }
        });
</script>